package me.leiusual.sharing.repository

import androidx.lifecycle.LiveData
import androidx.paging.Config
import androidx.paging.PagedList
import androidx.paging.toLiveData
import io.reactivex.Single
import me.leiusual.sharing.api.ApiSharing
import me.leiusual.sharing.api.model.ProductDetail
import me.leiusual.sharing.api.model.storeproductquery.Product
import me.leiusual.sharing.repository.datasource.ProductSearchDataSourceFactory
import javax.inject.Inject
import javax.inject.Singleton

/**
 * author: leiusual
 * create on: 2019-07-26
 * description:
 */
@Singleton
class ProductRepository @Inject constructor(
    private val apiSharing: ApiSharing
) {

  fun productSearch(keyword: String, storeId: Long): LiveData<PagedList<Product>> {
    return ProductSearchDataSourceFactory(apiSharing, keyword, storeId).toLiveData(Config(9, initialLoadSizeHint = 9))
  }

  fun productDetail(aid: Long?, mid: Long, r: Long?): Single<ProductDetail> {
    return apiSharing.productDetail(aid, mid, r)
  }
}